package org.datastructure.firstday.search;

import org.datastructure.firstday.recursion.Queen8;

public class InsertValueSearch {

    public static void main(String[] args) {
        int[] arr = {1, 2, 3, 4, 5, 6, 7, 8, 9};

        int i = insertValueSearch(arr, 0, arr.length - 1, 3);
        System.out.println(i);
    }


    public static int insertValueSearch(int[] arr, int left, int right, int findVal) {
        if (left > right || findVal < arr[left] || findVal > arr[right]) {
            return -1;
        }
        int mid = left + (right - left) / (arr[right] - arr[left]) * (findVal - arr[left]);
        int midVal = arr[mid];
        System.out.println("计数" + mid);
        if (findVal > midVal) { // 说明应该向右边递归
            return insertValueSearch(arr, mid + 1, right, findVal);
        } else if (findVal < midVal) { // 说明向左递归查找
            return insertValueSearch(arr, left, mid - 1, findVal);
        } else {
            return mid;
        }
    }
}
